<template>
	<view class="container">
		<z-paging ref="paging" :auto="true" v-model="bookList" @query="queryList">

			<!-- 自定义导航栏 -->
			<template #top>
				<!--  头部自定义导航栏高度 -->
				<view class="header-container">
					<!--  状态栏 -->
					<view class="status-bar" :style="{height:stateHeightValue+'px'}"></view>
					<!--  导航栏 -->
					<view class="nav-bar" :style="{height:navHeightValue+'px'}">

						<view class="back-button" @click="backToViewClick">
							<u-icon name="arrow-left" style="color: rgb(96, 98, 102);" size="22"></u-icon>
						</view>

						<!-- 搜索框自定义 -->
						<uni-search-bar class="search-bar" :placeholder="$t('bookSearch.placeholder')" :radius="100"
							@input="searchBookInfoClick" :cancelText="$t('common.cancel')"></uni-search-bar>
					</view>

				</view>

			</template>

			<view class="content-container">
				<!-- 书籍列表 -->
				<view class="book-item" v-for="(item,index) in bookList" :key="index">
					<view class="book-info">
						<view @click="enterBookInfoDetail(item)" class="book-detail">

							<view class="book-cover-container">
								<image class="book-cover" :src="item.bookIconUrl || '/static/default_cover.png'" lazy-load></image>
								<view class="book-cover-corner-tr"></view>
								<view class="book-cover-corner-bl"></view>
								<view class="book-shadow"></view>
							</view>

							<!-- 内容 -->
							<view class="book-text-content">
								<view class="book-title-container">
									<label class="book-title">{{item.bookName}}</label>
								</view>
								<view class="book-category-container">
									<label class="book-category">{{item.cateName}}</label>
								</view>
								<view class="book-intro-container">
									<label class="book-intro">{{item.intro}}</label>
								</view>

							</view>

						</view>
						<!-- 收藏按钮 -->
						<view class="collection-container">
							<view v-if="item.isCollection == true" class="collected-text">
								<label>{{$t('bookSearch.collected')}}</label>
							</view>
							<uni-icons v-if="item.isCollection == false" type="plus" size="26" color="#007AFF" class="collection-button"
								@click="addCollectionClick(index,item)"></uni-icons>
						</view>
					</view>
				</view>
			</view>
		</z-paging>
	</view>
</template>

<script>
	export default {

		data() {
			return {

				sysInfoRes: null,
				navHeightValue: 54,
				stateHeightValue: 0,
				mainNavHeightValue: 0,
				bookList: [],
				searchKey: ""
			}
		},
		components: {

		},
		onLoad() {



		},

		created() {


			this.sysInfoRes = uni.getSystemInfoSync();
			this.stateHeightValue = this.sysInfoRes.statusBarHeight;
			this.mainNavHeightValue = this.navHeightValue + this.stateHeightValue;




		},
		mounted() {


			// 请求tabs数据
			this.$refs.paging.reload();

		},
		methods: {

			async queryList(pageNo, pageSize) {

				var _this = this;
				var dataList = await this.requestSearchValueData(pageNo, pageSize);
				_this.$refs.paging.complete(dataList)

			},
			enterBookInfoDetail(e) {


				var bookInfoStr = JSON.stringify(e);
				uni.navigateTo({
					url: '/pages/baseBusiness/bookInfoDetail/bookInfoDetailView?bookInfo=' + bookInfoStr
				})

			},
			searchBookInfoClick(e) {

				this.searchKey = e;
				this.$refs.paging.reload();


			},
			backToViewClick() {
				uni.navigateBack()

			},

			//  网络请求区域
			async requestSearchValueData(pageNo, pageSize) {
				var dataRes = await this.$sqlDBConfig.selectCollectionTableData2()


				var that = this
				var param = {
					searchValue: that.searchKey,
					pageNum: pageNo,
					pageSize: pageSize,
				}

				var localHttp = that.$http_url.getHttpUrl();

				try {
					var res = await this.$api.getBookSearch(param);

					if (res.statusCode == 200) {
						var bookList = res.data.rows;
						bookList.forEach(function(item, index) {
							item.bookIconUrl = localHttp + "/images/" + item.bookCode + "/" + item.bookPic;
							item.isCollection = false;
							dataRes.forEach(function(item1, index1) {
								if (item1.bookcode == item.bookCode) {
									item.isCollection = true
								}
							})
						})
						return bookList;


					} else {
						return []
					}

				} catch (error) {
					console.log(error)
				}

			},
			addCollectionClick(index, item) {


				item.isCollection = true;
				var dataItems = [item];
				this.$sqlDBConfig.insertCollectionTableTableData(dataItems);

			}


		},
	}
</script>

<style scoped>
	.container {
		width: 100vw;
		height: 100vh;
		background-color: #f5f5f5;
	}
	
	.header-container {
		width: 100%;
		z-index: 9999;
		background-color: #ffffff;
		border-bottom: 1px solid #e4e7ed;
	}
	
	.status-bar {
		width: 100%;
		background-color: #ffffff;
	}
	
	.nav-bar {
		width: 100%;
		background-color: #ffffff;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		flex-direction: row;
	}
	
	.back-button {
		width: 40px;
		height: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.search-bar {
		width: calc(100% - 60px);
	}
	
	.content-container {
		padding: 10px;
	}
	
	.book-item {
		margin-bottom: 10px;
		border-radius: 8px;
		overflow: hidden;
		box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
	}
	
	.book-info {
		height: 134px;
		background-color: #ffffff;
		display: flex;
		flex-direction: row;
	}
	
	.book-detail {
		display: flex;
		flex-direction: row;
		width: calc(100% - 55px);
		padding: 10px;
	}
	
	.book-cover-container {
		width: 85px;
		height: 114px;
		position: relative;
		perspective: 1000px;
	}
	
	.book-cover {
		height: 100%;
		width: 100%;
		border-radius: 4px;
		transform-style: preserve-3d;
		transform: rotateY(0deg) translateZ(0);
		transition: transform 0.3s ease, box-shadow 0.3s ease;
		/* 增强立体感的阴影和质感 */
		background-color: #ffffff;
		box-shadow:
			0 4px 15px rgba(0, 0, 0, 0.2),
			-5px 0 10px rgba(0, 0, 0, 0.1),
			0 0 0 1px rgba(255, 255, 255, 0.5) inset;
		overflow: visible;
	}
	
	/* 书脊效果 - 更真实的立体书脊 */
	.book-cover::before {
		content: '';
		position: absolute;
		left: -8px;
		top: 0;
		bottom: 0;
		width: 8px;
		background: linear-gradient(
			90deg,
			#e5e5e5 0%,
			#f0f0f0 50%,
			#e5e5e5 100%
		);
		transform: rotateY(90deg) translateX(4px);
		transform-origin: right center;
		border-radius: 0 2px 2px 0;
		box-shadow: 0 0 5px rgba(0, 0, 0, 0.1) inset;
	}
	
	/* 仿真四个角效果 - 使用伪元素创建真实的书角立体感 */
	.book-cover::after {
		content: '';
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		border-radius: 4px;
		background: linear-gradient(
			135deg,
			rgba(255, 255, 255, 0.8) 0%,
			rgba(255, 255, 255, 0) 15%,
			rgba(0, 0, 0, 0) 85%,
			rgba(0, 0, 0, 0.1) 100%
		);
		pointer-events: none;
		z-index: 2;
	}
	
	/* 增强四个角的立体感 - 右上 */
	.book-cover-corner-tr {
		position: absolute;
		top: 0;
		right: 0;
		width: 10px;
		height: 10px;
		border-top-right-radius: 4px;
		background: linear-gradient(
			135deg,
			rgba(255, 255, 255, 0.9) 0%,
			rgba(255, 255, 255, 0) 70%
		);
		z-index: 3;
	}
	
	/* 增强四个角的立体感 - 左下 */
	.book-cover-corner-bl {
		position: absolute;
		bottom: 0;
		left: 0;
		width: 10px;
		height: 10px;
		border-bottom-left-radius: 4px;
		background: linear-gradient(
			315deg,
			rgba(0, 0, 0, 0.1) 0%,
			rgba(0, 0, 0, 0) 70%
		);
		z-index: 3;
	}
	
	.book-cover:active {
		transform: rotateY(10deg) rotateX(2deg) scale(1.05) translateZ(10px);
		box-shadow:
			0 8px 25px rgba(0, 0, 0, 0.3),
			-10px 0 20px rgba(0, 0, 0, 0.2),
			0 0 0 1px rgba(255, 255, 255, 0.5) inset;
	}
	
	.book-shadow {
		position: absolute;
		inset: 0;
		background: linear-gradient(
			135deg, 
			rgba(255,255,255,0.6) 0%, 
			rgba(255,255,255,0) 60%
		);
		border-radius: 4px;
		pointer-events: none;
	}
	
	.book-text-content {
		width: calc(100% - 95px);
		height: 114px;
		margin-left: 10px;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}
	
	.book-title-container {
		height: auto;
		min-height: 24px;
		display: flex;
		align-items: center;
		margin-bottom: 6px;
	}
	
	.book-title {
		font-weight: bold;
		font-size: 17px;
		color: #333;
		letter-spacing: 0.5px;
		line-height: 1.4;
	}
	
	.book-category-container {
		height: auto;
		min-height: 20px;
		display: flex;
		align-items: center;
		margin-bottom: 8px;
	}
	
	.book-category {
		color: #007AFF;
		font-size: 12px;
		background-color: #f0f8ff;
		padding: 3px 10px;
		border-radius: 12px;
		line-height: 1.4;
	}
	
	.book-intro-container {
		display: flex;
		align-items: flex-start;
		flex: 1;
	}
	
	.book-intro {
		display: -webkit-box;
		-webkit-line-clamp: 3;
		-webkit-box-orient: vertical;
		word-break: break-all;
		text-overflow: ellipsis;
		overflow: hidden;
		font-size: 12px;
		color: #666;
		line-height: 1.4;
	}
	
	.collection-container {
		width: 55px;
		height: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.collected-text {
		color: #888;
		font-weight: bold;
		width: 100%;
		height: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.collected-text label {
		color: #888;
		font-weight: bold;
		font-size: 12px;
	}
	
	.collection-button {
		transition: transform 0.2s ease;
	}
	
	.collection-button:active {
		transform: scale(1.2);
	}
</style>